package com.cskaoyan.controller;


import com.cskaoyan.aspect.OperationLog;
import com.cskaoyan.bean.*;
import com.cskaoyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @RequestMapping("list")
    public BaseRespVo orderList(Integer page, Integer limit, String sort, String order,
                                Short[] orderStatusArray, String orderSn, Integer userId){
        ItemsListVO<Order> orderListVO = orderService.selectOrderList(page, limit, sort, order,
                orderStatusArray, orderSn, userId);
        return BaseRespVo.ok(orderListVO);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){
        OrderDetailVO orderDetailVO = orderService.selectOrderDetailById(id);
        return BaseRespVo.ok(orderDetailVO);
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody RefundBO refundBO){
        Boolean b = orderService.refundOrder(refundBO);
        if (b) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.refundFail();
    }

    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody ShipBO shipBO){
        Integer shipOrder = orderService.shipOrder(shipBO);
        if (shipOrder != null) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("发货失败");
    }

}
